package cn.edu.huanu.controller;

import cn.edu.huanu.exception.BussiessException;
import cn.edu.huanu.pojo.User;
import cn.edu.huanu.service.UserService;
import cn.edu.huanu.service.impl.UserServcieImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author hb
 * @date 2025-10-17 16:05:11
 */
@WebServlet("*.user")
public class UserManagerAction extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");

        String servletPath = req.getServletPath();
        //提供业务层的实现
        UserService userService=new UserServcieImpl();
        PrintWriter out = resp.getWriter();

        if("/login.user".equals(servletPath)){
             String username=req.getParameter("username");
             String pwd=req.getParameter("pwd");
             try{
                 User user = userService.login(username, pwd);
                 out.println(user);
             } catch (BussiessException e) {
                 out.println(e.getMessage());
             }

        }
    }
}
